package com.dfbz.netctoss.mapper;


import com.dfbz.netctoss.entity.AdminInfo;
import com.dfbz.netctoss.entity.Privilege;
import com.dfbz.netctoss.entity.Role;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface AdminInfoMapper extends Mapper<AdminInfo> {

    @Select("select ai.* from admin_info ai where admin_code = #{admincode}")
    AdminInfo findByAdmincode(@Param("admincode") String admincode);

    @Select("select admin_info.* from admin_info where admin_code = #{adminCode}")
    @Results(
            {
                    @Result(property = "adminId", column = "admin_id", id=true),
                    @Result(property = "roles",column = "admin_id",
                            many = @Many(select = "com.dfbz.netctoss.mapper.RoleMapper.findRolesByAdminId"))
            }

    )
    AdminInfo findRolesByAdminCode(@Param("adminCode") String adminCode);

    @Select("select pr.* " +
            "from role_privilege rp, privilege pr " +
            "where pr.privilege_id = rp.privilege_id " +
            "and rp.role_id = #{roleId}")
    List<Privilege> selectAllPrivilegeByRId(@Param("roleId") int roleId);

    @Select("select admin_info.* from admin_info where admin_code = #{adminCode}")
    AdminInfo selectByName(@Param("adminCode") String adminCode);

    @Select("select ai.* from admin_info ai")
    @Results(
            {
                    @Result(property = "adminId", column = "admin_id", id=true),
                    @Result(property = "roles",column = "admin_id",
                            many = @Many(select = "com.dfbz.netctoss.mapper.RoleMapper.findRolesByAdminId"))
            }

    )
    List<AdminInfo> selectAllAdmin();
}